﻿using Appliaction.Dto.Sinv;
using Appliaction.IAppServices.Sinv;
using AutoMapper;
using Domain.Entitys.Sinv;
using Domain.IRepositorys.Sinv;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Appliaction.AppServices.Sinv
{
    public class Sinv_Sale_OutboundService : ISinv_Sale_OutboundService
    {
        private readonly ISinv_Sale_OutboundRepository sinv_Sale_OutboundRepository;
        private readonly IMapper mapper;

        public Sinv_Sale_OutboundService(ISinv_Sale_OutboundRepository sinv_Sale_OutboundRepository,IMapper mapper)
        {
            this.sinv_Sale_OutboundRepository = sinv_Sale_OutboundRepository;
            this.mapper = mapper;
        }

        /// <summary>
        /// 根据销售出库编号查询对应销售出库信息
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public async Task<Sinv_Sale_Outbound> GetSinv_Sale_OutboundByCodeAsync(string code)
        {
            return await sinv_Sale_OutboundRepository.GetSinv_Sale_OutboundByCodeAsync(code);
        }

        /// <summary>
        /// 根据销售出库编号查询销售出库明细
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public async Task<List<Sinv_Sale_Outbound_Details>> GetSinv_Sale_Outbound_DetailsByCodeAsync(string code)
        {
            return await sinv_Sale_OutboundRepository.GetSinv_Sale_Outbound_DetailsByCodeAsync(code);
        }

        /// <summary>
        /// 分页条件查询销售出库信息及其明细
        /// </summary>
        /// <param name="currentPage"></param>
        /// <param name="pageSize"></param>
        /// <param name="customerName"></param>
        /// <param name="orderCode"></param>
        /// <returns></returns>
        public List<Sinv_Sale_Outbound_Info> GetSinv_Sale_Outbound_Infos(int currentPage, int pageSize, string customerName, string orderCode, int orderStatus, char auditStatus)
        {
            return sinv_Sale_OutboundRepository.GetSinv_Sale_Outbound_Infos(currentPage,pageSize,customerName,orderCode,orderStatus,auditStatus);
        }

        /// <summary>
        /// 添加销售出库信息及其详情
        /// </summary>
        /// <param name="saleOutboundWithDetailsDto"></param>
        /// <returns></returns>
        public async Task<int> Sinv_Sale_OutboundAddAsync(SaleOutboundWithDetailsDto<Sinv_Sale_OutboundAddDto> saleOutboundWithDetailsDto)
        {
            Sinv_Sale_Outbound sinv_Sale_Outbound = mapper.Map<Sinv_Sale_Outbound>(saleOutboundWithDetailsDto.Sinv_Sale_OutboundDto);
            List<Sinv_Sale_Outbound_Details> sinv_Sale_Outbound_Details = mapper.Map<List<Sinv_Sale_Outbound_Details>>(saleOutboundWithDetailsDto.Sinv_Sale_Outbound_DetailsAddDtos);
            //Sinv_Sale_Order sinv_Sale_Order = mapper.Map<Sinv_Sale_Order>(saleOutboundWithDetailsDto.Sinv_Sale_OrderStatusUpdate);
            return await sinv_Sale_OutboundRepository.Sinv_Sale_OutboundAddAsync(sinv_Sale_Outbound,sinv_Sale_Outbound_Details);
        }

        /// <summary>
        /// 修改销售出库订单审核状态，减少库存，增加销售明细出库数量，修改销售订单出库状态
        /// </summary>
        /// <param name="sinv_Sale_Outbound"></param>
        /// <returns></returns>
        public async Task<int> Sinv_Sale_OutboundAuditUpdateAsync(Sinv_Sale_OutboundAuditUpdateDto sinv_Sale_Outbound)
        {
            Sinv_Sale_Outbound sale_Outbound = mapper.Map<Sinv_Sale_Outbound>(sinv_Sale_Outbound);
            return await sinv_Sale_OutboundRepository.Sinv_Sale_OutboundAuditUpdateAsync(sale_Outbound);
        }

        /// <summary>
        /// 条件拆线呢销售出库总数
        /// </summary>
        /// <param name="customerName"></param>
        /// <param name="orderCode"></param>
        /// <returns></returns>
        public Task<int> Sinv_Sale_OutboundCountAsync(string customerName, string orderCode, int orderStatus, char auditStatus)
        {
            return sinv_Sale_OutboundRepository.Sinv_Sale_OutboundCountAsync(customerName,orderCode,orderStatus,auditStatus);
        }

        /// <summary>
        /// 逻辑删除销售出库信息
        /// </summary>
        /// <param name="sinv_CustomerDelDto"></param>
        /// <returns></returns>
        public async Task<int> Sinv_Sale_OutboundDelAsync(Sinv_Sale_OutboundDelDto sinv_CustomerDelDto)
        {
            Sinv_Sale_Outbound sinv_Sale_Outbound = mapper.Map<Sinv_Sale_Outbound>(sinv_CustomerDelDto);
            return await sinv_Sale_OutboundRepository.Sinv_Sale_OutboundDelAsync(sinv_Sale_Outbound);
        }

        /// <summary>
        /// 修改销售出库信息及其详情
        /// </summary>
        /// <param name="saleOutboundWithDetailsUpdateDto"></param>
        /// <returns></returns>
        public async Task<int> Sinv_Sale_OutboundUpdateAsync(SaleOutboundWithDetailsUpdateDto saleOutboundWithDetailsDto)
        {
            Sinv_Sale_Outbound sinv_Sale_Outbound = mapper.Map<Sinv_Sale_Outbound>(saleOutboundWithDetailsDto.Sinv_Sale_OutboundUpdateDto);
            return await sinv_Sale_OutboundRepository.Sinv_Sale_OutboundUpdateAsync(sinv_Sale_Outbound, saleOutboundWithDetailsDto.Sinv_Sale_Outbound_Details);
        }
    }
}
